﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using APJ.ComLib.Business.System.Interface;
using APJ.ComLib.Model.Context;
using APJ.ComLib.Model.System;

namespace APJ.ComLib.WebApp01.Controllers.System
{
    public class SystemParametersController : Controller
    {
        private readonly ISystemParameterRepository _systemParameterRepository;

        public SystemParametersController(ISystemParameterRepository systemParameterRepository)
        {
            _systemParameterRepository = systemParameterRepository;
        }

        // GET: SystemParameters
        public ActionResult Index()
        {
            return View(_systemParameterRepository.ListAll()); 
        }

        // GET: SystemParameters/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            SystemParameter systemParameter = _systemParameterRepository.GetByID(id);
            if (systemParameter == null)
            {
                return HttpNotFound();
            }
            return View(systemParameter);
        }

        // GET: SystemParameters/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: SystemParameters/Create
        // 为了防止“过多发布”攻击，请启用要绑定到的特定属性，有关 
        // 详细信息，请参阅 https://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "SystemParaID,SystemParaKey,SystemParaValue,CreatedBy,CreatedDate,LastUpdatedBy,LastUpdatedDate")] SystemParameter systemParameter)
        {
            if (ModelState.IsValid)
            {
                _systemParameterRepository.Add(systemParameter);
                
                return RedirectToAction("Index");
            }

            return View(systemParameter);
        }

        // GET: SystemParameters/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            SystemParameter systemParameter = _systemParameterRepository.GetByID(id);
            if (systemParameter == null)
            {
                return HttpNotFound();
            }
            return View(systemParameter);
        }

        // POST: SystemParameters/Edit/5
        // 为了防止“过多发布”攻击，请启用要绑定到的特定属性，有关 
        // 详细信息，请参阅 https://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "SystemParaID,SystemParaKey,SystemParaValue,CreatedBy,CreatedDate,LastUpdatedBy,LastUpdatedDate")] SystemParameter systemParameter)
        {
            if (ModelState.IsValid)
            {                
                _systemParameterRepository.Edit(systemParameter);
                return RedirectToAction("Index");
            }
            return View(systemParameter);
        }

        // GET: SystemParameters/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            SystemParameter systemParameter = _systemParameterRepository.GetByID(id);
            if (systemParameter == null)
            {
                return HttpNotFound();
            }
            return View(systemParameter);
        }

        // POST: SystemParameters/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            SystemParameter systemParameter = _systemParameterRepository.GetByID(id);
            _systemParameterRepository.Remove(systemParameter);

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                //db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
